from django.http import HttpResponse, response

# 创建一个HttpResponse对象
response = HttpResponse("设置 cookie")

# 设置cookie
def set_cookie(request):
    # 设置cookie，键值对
    response.set_cookie("username", "super",max_age=3600)  # 过期时间为1小时(3600秒)
    return response

def get_cookie(request):
    # 获取cookie
    username = request.COOKIES.get("username")  
    return HttpResponse(f"读取cookie成功,用户名:{username}")

def del_cookie(request):
    # 删除cookie
    response.delete_cookie("username")  # 删除名为"username"的cookie
    
    
    return response